package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.view.ViewGroup
import com.starsea.book.base.adapter.ItemViewHolder
import com.starsea.book.base.adapter.RecyclerAdapter
import com.starsea.book.databinding.ItemWalletListContentBinding
import com.starsea.book.ui.newpage.entity.WalletListDataEntity
import com.starsea.book.ui.newpage.utils.finialDouble
import com.starsea.book.ui.widget.recycler.ItemTouchCallback

class LotteryRecordAdapter(
    context: Context,
    var type: Int,
    var onChanged: ((value: WalletListDataEntity) -> Unit)? = null
) :
    RecyclerAdapter<WalletListDataEntity, ItemWalletListContentBinding>(context),
    ItemTouchCallback.Callback {


    override fun getViewBinding(parent: ViewGroup): ItemWalletListContentBinding {
        return ItemWalletListContentBinding.inflate(inflater, parent, false)
    }

    override fun registerListener(holder: ItemViewHolder, binding: ItemWalletListContentBinding) {
        binding.root.setOnClickListener {
            getItem(holder.layoutPosition)?.let {
                onChanged!!.invoke(it)
            }

        }
    }

    override fun convert(
        holder: ItemViewHolder,
        binding: ItemWalletListContentBinding,
        item: WalletListDataEntity,
        payloads: MutableList<Any>
    ) {
        binding.run {
//            余额操作 1、增加 2、减少
            tvNum.text = "+${
                (item.amount ?: "").toDouble().finialDouble()
            }${if (item.amountType == 1) "金币" else "天"}"

            tvTitle.text = if (item.amountType == 1) "金币" else "会员"


        }
    }
}